package com.atguigu.juc;

import java.util.Timer;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

public class DeadLockDemo2 {
    static ReentrantLock locka=new ReentrantLock();
    static ReentrantLock lockb=new ReentrantLock();
    public static void main(String[] args) {
        new Thread(()->{
            synchronized (locka){
                System.out.println(Thread.currentThread().getName()+"\t"+"------run over...");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (lockb) {
                    System.out.println(Thread.currentThread().getName()+"\t"+"------run over...");
                }
            }
        },"A").start();

        new Thread(()->{
            synchronized (lockb){
                System.out.println(Thread.currentThread().getName()+"\t"+"------run over...");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (locka){
                    System.out.println(Thread.currentThread().getName()+"\t"+"------run over...");
                }
            }
        },"B").start();
    }

}
